﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="EclassManage.aspx.cs" Inherits="Educational_Eclass_EclassManage" %>
<script type="text/javascript">
window.addEvent('domready',function(){
    window.addFormCheckForEclass=function(){
        new FormCheck('formAddForEclass',{display:{tipsPosition:'left'},submit:false,onValidateSuccess:function(){
            MUI.showModalMessage('正在添加班级');
            new Request.JSON({url:'../Ajax/EclassManage.aspx?Action=saveAddEclass',noCache:true,onSuccess:function(result){
                MUI.hideModalMessage();
                if(result.error)
                    MUI.appendStatusMessage({'text':result.msg});
                else
                {
                    $('windowAddForEclass').retrieve('instance').close();
                    MUI.appendStatusMessage({'text':result.msg});
                    window.datagridForEclass.loadData();
                }
	        },onFailure:function(error){
		        MUI.appendStatusMessage({'text':'AJAX提交表单的过程中发生未知错误。'});
		        MUI.hideModalMessage();
            }}).post($('formAddForEclass'));
        }});   
    };
    window.showAddFormForEclass=function(){
        MUI.openContentByWindow('windowAddForEclass','添加班级',$('formContainerForEclass'),$('formAddForEclass'),400,120);
    };
    
    window.updateFormCheckForEclass=function(){
        new FormCheck('formUpdateForEclass',{display:{tipsPosition:'left'},submit:false,onValidateSuccess:function(){
            MUI.showModalMessage('正在修改班级');
            new Request.JSON({url:'../Ajax/EclassManage.aspx?Action=saveUpdateEclass',noCache:true,onSuccess:function(result){
                MUI.hideModalMessage();
                if(result.error)
                    MUI.appendStatusMessage({'text':result.msg});
                else
                {
                    $('windowUpdateForEclass').retrieve('instance').close();
                    MUI.appendStatusMessage({'text':result.msg});
                    window.datagridForEclass.loadData();
                }
	        },onFailure:function(error){
		        MUI.appendStatusMessage({'text':'AJAX提交表单的过程中发生未知错误。'});
		        MUI.hideModalMessage();
            }}).post($('formUpdateForEclass'));
        }});   
    };
    window.showUpdateFormForEclass=function(){
        var indices = window.datagridForEclass.getSelectedIndices();
        if (indices.length == 0)
	    {
		    MUI.showModalAlert('您必须至少选定一行');
		    return;
	    }
	    if (indices.length > 1)
	    {
		    MUI.showModalAlert('修改时不允许一次修改多行数据。。');
		    return;
	    }
	    var selectedData=window.datagridForEclass.getDataByRow(indices[0]);
	    var element=$('formUpdateForEclass');
	    element.getElement('input[name=eclassId]').set('value',selectedData.eclassId);
	    element.getElement('input[name=eclassName]').set('value',selectedData.eclassName);
	    element.getElement('input[name=leaderId]').set('value',selectedData.leader.teacherId);
	    element.getElement('#leaderName2').set('value',selectedData.leader.teacherName);
	    Util.setSelectedValue('gradeId2',selectedData.grade.gradeId);
	    Util.setSelectedValue('status',selectedData.status);
        MUI.openContentByWindow('windowUpdateForEclass','修改班级',$('formContainerForEclass'),$('formUpdateForEclass'),400,150);
    };
    
    window.deleteForEclass=function(){
        var indices = window.datagridForEclass.getSelectedIndices();
        if (indices.length == 0)
	    {
		    MUI.showModalAlert('您必须至少选定一行');
		    return;
	    }
	    var selectedData=window.datagridForEclass.getDataByRow(indices[0]);
	    MUI.showConfirm('您确定要删除所选定的数据？此操作不可恢复！',function(){
	        MUI.showModalMessage('正在删除所选中的数据');
	        new Request.JSON({url:'../Ajax/EclassManage.aspx?Action=deleteEclass&eclassId='+selectedData.eclassId.toString(),noCache:true,onSuccess:function(result){
	            MUI.hideModalMessage();
                if(result.error)
                    MUI.appendStatusMessage({'text':result.msg});
                else
                {
                    MUI.appendStatusMessage({'text':result.msg});
                    window.datagridForEclass.loadData();
                }
            },onFailure:function(error){
	            MUI.appendStatusMessage({'text':'AJAX提交表单的过程中发生未知错误。'});
	            MUI.hideModalMessage();
            }}).get();
        });
    };
    
    window.loadDataForEclass=function(){
        window.datagridForEclass = new omniGrid('dataListForEclass', {
            columnModel: [
                {header: '班级ID',dataIndex: 'eclassId',dataType:'number',width:80,sortable:true},
                {header: '班级名称',dataIndex: 'eclassName',dataType:'string',width:120,sortable:true},
                {header: '班主任姓名',dataIndex: 'eclassId',dataType:'string',width:100,sortable:false,labelFunction:function(rowdata, r, columnModel){
                    return rowdata.leader.teacherName;
                }},
                {header: '年级',dataIndex: 'eclassId',dataType:'string',width:70,sortable:false,labelFunction:function(rowdata, r, columnModel){
                    if($defined(rowdata.grade.gradeName))
                        return rowdata.grade.gradeName;
                    else
                        return '&nbsp;';
                }},
                {header: '注册时间',dataIndex: 'createTime',dataType:'string',width:150,sortable:true},
                {header: '状态',dataIndex: 'eclassId',dataType:'number',width:70,labelFunction:function(rowdata, r, columnModel){
                    if(rowdata.status==1)
                        return '<span style="color:#0000FF">已毕业</span>';
                    if(rowdata.status==9)
                        return '正常';
                }}
            ],
            buttons : [
                {name: '添加', bclass: 'add', onclick : window.showAddFormForEclass},
                {name: '修改', bclass: 'update', onclick : window.showUpdateFormForEclass},
                {name: '删除', bclass: 'delete', onclick : window.deleteForEclass}
            ],
            url:'../Ajax/EclassManage.aspx?Action=search',
            perPageOptions: [20,50,100,200,500,1000],
            perPage:20,
            height:$('dataListForEclass').getParent().getParent().getStyle('height').toInt(),
            serverSort:false,
            multipleSelection:false,
            sortHeader:true,
            pagination:true
        });
    };

    window.binddingEventForEclass=function(){
        $('formAddForEclass').getElement('.selectLeader').addEvent('click',function(){
            MUI.openChildByModalWindow('selectLeaderForAddEclass','选择教师','../Teacher/SelectTeacher.aspx?windowId=selectLeaderForAddEclass&teacherId=leaderId&teacherName=leaderName',700,400);
        });
        $('formUpdateForEclass').getElement('.selectLeader').addEvent('click',function(){
            MUI.openChildByModalWindow('selectLeaderForUpdateEclass','选择教师','../Teacher/SelectTeacher.aspx?windowId=selectLeaderForUpdateEclass&teacherId=leaderId2&teacherName=leaderName2',700,400);
        });
    };
    
    window.initializeForEclass=function(){
        new ZebraTable({elements:'table.tableFixed'});
        window.loadDataForEclass();
        window.binddingEventForEclass();
        window.addFormCheckForEclass();
        window.updateFormCheckForEclass();
    };
    
    window.initForEclass=function(){
        window.initializeForEclass();
    };
    
    window.initForEclass();
});
</script>
<div id="dataListForEclass"></div>
<!--隐藏的表单-->
<div id="formContainerForEclass" style="display:none;">

<!--添加表单-->
<form id="formAddForEclass">
<input type="hidden" id="leaderId" name="leaderId" />
<table class="tableFixed" border="0" cellpadding="0" cellspacing="0" width="100%">
    <tr>
        <td class="tableLeft1">班级名称：</td>
        <td class="tableLeft2"><input class="input validate['required','length[2,20]']" name="eclassName" type="text" /></td>
    </tr>
    <tr>
        <td class="tableLeft1">所属年级：</td>
        <td class="tableLeft2"><%=selectStr %></td>
    </tr>
    <tr>
        <td class="tableLeft1">班主任：</td>
        <td class="tableLeft2"><input id="leaderName" class="input validate['required']" style="width:70px;" type="text" readonly="readonly" />&nbsp;<input type="button" class="selectLeader button" value="选择" /></td>
    </tr>
    <tr>
        <td class="tableLeft1"></td>
        <td class="tableLeft2"><input class="submit button validate['submit']" type="button" value="提交添加" /></td>
    </tr>
</table>
</form>
<!--修改表单-->
<form id="formUpdateForEclass">
<input type="hidden" name="eclassId" />
<input type="hidden" id="leaderId2" name="leaderId" />
<table class="tableFixed" border="0" cellpadding="0" cellspacing="0" width="100%">
    <tr>
        <td class="tableLeft1">班级名称：</td>
        <td class="tableLeft2"><input class="input validate['required','length[2,20]']" name="eclassName" type="text" /></td>
    </tr>
    <tr>
        <td class="tableLeft1">班级状态：</td>
        <td class="tableLeft2">
            <select id="status" name="status" class="input">
                <option value="9">正常</option>
                <option value="1">已毕业</option>
            </select>
        </td>
    </tr>
    <tr>
        <td class="tableLeft1">所属班级：</td>
        <td class="tableLeft2"><%=selectStr2 %></td>
    </tr>
    <tr>
        <td class="tableLeft1">班主任：</td>
        <td class="tableLeft2"><input id="leaderName2" class="input validate['required']" style="width:70px;" type="text" readonly="readonly" />&nbsp;<input type="button" class="selectLeader button" value="选择" /></td>
    </tr>
    <tr>
        <td class="tableLeft1"></td>
        <td class="tableLeft2"><input class="submit button validate['submit']" type="button" value="提交修改" /></td>
    </tr>
</table>
</form>
</div>